$(function(){
		$("#zone_left .list-group").height(window.innerHeight - 225),
		$("#div_msgpanel").width(.52 * (window.innerWidth - 100)),
		$("#div_msgpanel").height(window.innerHeight - 200),
		$("#div_msgbox").height(window.innerHeight - 246),
		$("#div_privmsg").height(window.innerHeight - 246),
		$(".hotrooms_title").width(window.innerWidth - 340 - $("#div_msgpanel").width()),
		$("#hotrooms").height($("#div_msgbox").height()),
		$("#zone_left").show(),
		$("#zone_center").show(),
		$("body").show();
		//发送消息
		$("#btn_say").click(function() {
			var a = $.trim($("#inp_say").val());
			if (!a) return layer.msg("不能输入空字符");
			let mm = emoji[a];
			let action = "string";
			sendMessage(a,action);
			$("#inp_say").val("")
		
		});
		//点击上传图片功能
		$("#a_uploadfile").click(function() {
			document.getElementById("uploading_file").click()
		});
		//上传图片
		$("#uploading_file").change(function() {
			var a = document.getElementById("uploading_file").files[0];
			var reader = new FileReader();
			reader.onload = function(evt){
				var imgstr = evt.target.result;
				sendMessage(imgstr,"gif");
				document.getElementById("uploading_file").value = "";//清空input file
			};     
			reader.readAsDataURL(a);
		});
		//清除聊天记录
		 $("#msg_clear").click(function() {
			var a = layer.confirm("是否确定清除记录？", {
				skin: "demo-class",
				btn: ["确定", "取消"]
			},
			function() {
				layer.close(a),
				$("#div_msgbox").html("")
			})
		});
		//撤销消息
		 $("#msg_back").click(function() {
			var b = layer.confirm("是否确定撤回最新消息？", {
				skin: "demo-class",
				btn: ["确定", "取消"]
			},
			function() { 
				layer.close(b);
			})
		});
		//涂鸦信息
		$("#a_doodle").click(function() {
			index_doodle = layer.open({
			        type: 2,
			        title: !1,
			        closeBtn: 0,
			        shadeClose: !0,
			        skin: "layui-layer-rim",
			        area: ["856px", "515px"],
			        content: ["doodle.html", "no"]
			   });
		});
		//录音
		$("#a_record").click(function() {
			init_record()
		});
		//拍照
		$("#a_getphoto").click(function() {
			init_getphoto()
		})
		
		$(".userList").click(function(){
			console.log(this);
		});

});

function showImages(images){
	layer.open({
		type: 2,//1:本地  2:url
		title: '图片查看',
		shadeClose: true,
		shade: 0.6,//遮罩层
		area: ['90%', '90%'],
		anim:1,//动画  -1不显示
		content: images
	});

}

//创建房间
function click_hotroom(name){
	var a = "<div class='inroom_zone'><div class='inroom_leftzone'><input id='inp_roomname' type='text' placeholder='房间名' style='width:170px;margin:12px 10px;' maxlength='10' class='form-control'/><input id='inp_roompsw' type='text' placeholder='密码（默认空）' style='width:170px;margin:20px 10px;' maxlength='6' class='form-control' /><button id='inroom_ok' class='btn btn-success' style='margin:0px 10px;width:170px;' type='button'>进入</button></div><div class='inroom_rightzone' style='overflow-y:auto;'>asdf</div></div>";
    index_inroom = layer.open({
        type: 1,
        title: "进入/创建房间",
        skin: "demo-class",
        shadeClose: !0,
        closeBtn: 0,
        area: ["400px", "240px"],
        content: a
    });
    if(name != undefined){
    	$("#inp_roomname").attr("disabled",true);
    	$("#msg_title").html(name);
    	$("#inp_roomname").val(name);
    }
    $("#inroom_ok").click(function() {
       fun_loading(!0);
    })
}
//进度条
function fun_loading(a) {
		a ? index_loading = layer.load() : layer.close(index_loading)
}

function sendPersion(data){
	var name = $(data).find(".nickname").html();
	$("#msg_title").html('和[<span style="color:orange">'+name+'</span>]的聊天记录')
}

function result_doodle(a) {
    layer.close(index_doodle);    
    sendMessage(a,"gif");
}

$.fn.extend({
	insertAtCaret: function(a) {
		var c, d, e, b = $(this)[0];
		document.selection ? (this.focus(), sel = document.selection.createRange(), sel.text = a, this.focus()) : b.selectionStart || "0" == b.selectionStart ? (c = b.selectionStart, d = b.selectionEnd, e = b.scrollTop, b.value = b.value.substring(0, c) + a + b.value.substring(d, b.value.length), this.focus(), b.selectionStart = c + a.length, b.selectionEnd = c + a.length, b.scrollTop = e) : (this.value += a, this.focus())
	}
})


